package com.qingzhuge.manager.autoconfigure;

import com.google.gson.Gson;
import com.qingzhuge.sys.entity.SysConfig;
import com.qingzhuge.sys.entity.SysSiteConfig;
import com.qingzhuge.sys.service.ISysConfigService;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

import static com.qingzhuge.sys.entity.SysSiteConfig.SYS_SITE_CONFIG_KEY;

/**
 * @author : zero.xiao
 * @description : 添加系统默认角色和用户
 * @date :2018/9/20 0020 下午 16:21
 * @modified :
 * @since : 1.0.0
 */
@Order(4)
@Component
public class SysSiteRunner implements ApplicationRunner {
    @Resource
    private ISysConfigService configService;

    @Override
    public void run(ApplicationArguments args) {

        SysSiteConfig site = configService.getConfigObject(SYS_SITE_CONFIG_KEY,SysSiteConfig.class);
        if (null == site){
            site = new SysSiteConfig();
            site.setName("青竹阁软件");
            site.setVersion("1.0.0");
            site.setEnable(true);
            SysConfig config = new SysConfig();
            config.setId(site.getId());
            config.setKey(SYS_SITE_CONFIG_KEY);
            config.setValue(new Gson().toJson(site));
            configService.save(config);
        }
    }
}